home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3081 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.itd.umich.edu!usenet
  2. From: Chris Lahey <clahey@umich.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: problems with a linked list
  5. Date: 25 Jan 1996 23:01:40 GMT
  6. Organization: University of Michigan
  7. Message-ID: <4e924k$o9c@lastactionhero.rs.itd.umich.edu>
  8. References: <1996Jan25.125329.23499@dcs.warwick.ac.uk>
  9. NNTP-Posting-Host: rep00703.reshall.umich.edu
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.12 (X11; I; Linux 1.2.13 i586)
  14. X-URL: news:1996Jan25.125329.23499@dcs.warwick.ac.uk
  15.  
  16. Sorry I can't quote you.  This newsreader sucks.  BUT:
  17.  
  18.  
  19. I think that your problem is that you are passing the value firstside to a
  20. function and then assigning a value to it and expecting the value to have
  21. changed when you return to main.  
  22.  
  23. One conceptual problem you may have is that you are using the same name in main
  24. and in your add_side function.  C doesn't care (the add_side function can't see
  25. main's copy) but unless you pay close attention you may think that they are the
  26. same variable.
  27.  
  28. When you pass the variable to add_side the C compiler creates code to send the
  29. value of first_side to the function.  Even though the value in first_side is a
  30. pointer, the value is passed.  You can change the data that the pointer points
  31. at but not if you change the pointer main won't see it.
  32.  
  33. One possible solution would be to change main() so that it passes a pointer to
  34. a pointer to your struct and change add_side() correspondingly.  Another would
  35. be a reorganization of the program, keeping the problem in mind (perhaps have
  36. add_side see the global variable.  This is considered by some to be bad style.)
  37.  
  38.